package com.xinshujia.wxxcx.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.xinshujia.wxxcx.mapper.DeviceMapper;
import com.xinshujia.wxxcx.service.ThresholdService;
import com.xinshujia.wxxcx.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Cui Han
 * @Date 2024/4/12 11:19
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/threshold")
public class ThresholdController {

    @Autowired
    private ThresholdService thresholdService;


    /**
     * 根据机床id查询当前机床阈值修改记录
     * @param machineId
     * @return
     */
    @GetMapping("/findThresholdInfo")
    @SaCheckLogin
    public Result findThresholdInfo(Long  machineId){
        return Result.ok(thresholdService.findThresholdInfo(machineId));
    }


    /**
     * 查询当前阈值
     * @return
     */
    @GetMapping("/findThreshold")
    @SaCheckLogin
    public Result findThreshold(String guid){
        return Result.ok(thresholdService.findThreshold(guid));
    }


    /**
     * 报警开关
     * @param value
     * @return
     */
    @GetMapping("/alarmSwitch")
    @SaCheckLogin
    public Result alarmSwitch(Integer value,String guid){
        return Result.ok(thresholdService.alarmSwitch(value,guid));
    }

    /**
     * 清除报警
     * @return
     */
    @GetMapping("clearAlarm")
    @SaCheckLogin
    public Result clearAlarm(String guid,Long machineId){
        return Result.ok(thresholdService.clearAlarm(guid,machineId));
    }


    /**
     * 修改阈值
     * @param
     * @return
     */
    @GetMapping("/updateThreshold")
    @SaCheckLogin
    public Result updateThreshold(String guid,Long machineId,Double x,Double y,Double z){
        return Result.ok(thresholdService.updateThreshold( guid,machineId,x,y,z));
    }

    /**
     * 机床停机时将阈值改为保底值
     */
    public void  updateAllThreshold(){
        thresholdService.updateAllThreshold();
    }

    /**
     * 机床加工时将阈值改为加工时的最大震动值
     */
    public void updateThresholdTime(){
        thresholdService.updateThresholdTime();
    }


    /**
     * 查找所以设备
     * @return
     */
    @GetMapping("findDevice")
    public Result findDevieve(){
        return Result.ok(thresholdService.findDevieve());
    }

    /**
     * 修改设备基准值和保底值
     * @param standard
     * @param minimum
     * @param id
     * @return
     */
    @GetMapping("updateDevice")
    public Result updateDevice(Double standard,Double minimum,Integer id,Double percentage,Double operation){
        return Result.ok(thresholdService.updateDevice(standard,minimum,id,percentage,operation));
    }
}

